package com.wy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wy.bean.Goods;
import com.wy.service.GoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @RequestMapping("list")
    public String list(Goods goods, Model model, @RequestParam(defaultValue = "1") int pageNum,
                       @RequestParam(defaultValue = "3") int pageSize
                       ){
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> list = goodsService.list(goods);
        PageInfo<Goods> pageInfo = new PageInfo<>(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("list",list);
        model.addAttribute("goods",goods);
        return "list";
    }
}
